class Membership < ActiveRecord::Base
  #Relations
  belongs_to :band, :class_name => "Artist"
  belongs_to :member, :class_name => "Artist" 
  has_many :membership_dates, :dependent => :destroy

  #validate to ensure a person isn't added to another person, or itself

  #
  attr_protected :member_id, :band_id

  #Callbacks
  after_update :create_edit
  after_create :new_entry_edit
  
  private

  def new_entry_edit
    entry = Hash.new
    entry.store("Added", [band.name, member.name])
    Edit.create_edit(entry, band)
  end

  def create_edit
    if self.changed?
      Edit.create_edit(self.changes, member)
    end
  end
end
